﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Kevin.Controls
{
    public class MenuLevel2 :Control
    {
        public MenuLevel2() { }

        public string MenuID
        {
            get;
            set;
        }

        public string MenuContolID
        {
            get;
            set;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            CreateMenuLevel2();
        }

        private void CreateMenuLevel2()
        {
            if (string.IsNullOrEmpty(this.MenuContolID))
            {
                throw new Exception("请设定MenuContolID，如有疑问请联系我(席吉波)");
            }

            LeftMenu menu = (LeftMenu)base.FindControl(this.MenuContolID);

            DataList dl = new DataList();
            dl.RepeatColumns = 2;

            List<MenuItem> menuList = menu.MenuList;
            var item = (MenuItem)(from m in menuList
                        where m.ID == this.MenuID
                        select m);
            string strTable_S = @" <table width='90%' border='0' cellspacing='20' cellpadding='0' class='mgb10'>";
            string strTable_E = "</table>";
            string strTableRow = "<tr>{0}</tr>";
            string strTableTd1 = @"<td width='50%' align='center'>
                                        <a href='{0}' title='{1}'>
                                            <img src='{2}' width='264' height='139'/></a>
                                    </td>";
            string strTableTd2 = @"<td width='25%' align='left'>
                                        <a href='{}' title='一线出口——保税出境'>
                                            <img src='../Masterimages/Yl_2.jpg' width='264' height='139' /></a>
                                    </td>";
            string strHas3Menu = @"<tr align='center'>
                                      <td width='50%' align='center'><div class='{0}'><table width='108' border='0' cellspacing='0' cellpadding='0'>
                                     <tr>
                                      <td><a href='../Apps/Elmis/FrmWL_TU_CAF_BILLSList.aspx?strProjectType=1&strIEFlag=I&strIOType=FI'><img src='../MasterImages/btn_01.jpg' width='108' height='30' style='filter: Alpha(opacity=50);-moz-opacity:.1;opacity:0.1;' /></a></td>
                                     </tr>
                                     <tr>
                                      <td><a href='../Apps/Elmis/FrmWL_TU_CAF_BILLSList.aspx?strProjectType=2&strIEFlag=I&strIOType=FI'><img src='../MasterImages/btn_02.jpg' width='108' height='30' /></a></td>
                                     </tr>
                                     <tr>
                                      <td><a href='../Apps/Elmis/FrmWL_TU_CAF_BILLSList.aspx?strProjectType=B&strIEFlag=I&strIOType=FI'><img src='../MasterImages/btn_03.jpg' width='108' height='30' /></a></td>
                                     </tr>
                                     <tr>
                                      <td><a href='../Apps/Elmis/FrmWL_TU_CAF_BILLSList.aspx?strProjectType=7&strIEFlag=I&strIOType=FI'><img src='../MasterImages/btn_04.jpg' width='108' height='30' /></a></td>
                                 </tr>";
            string strNone3Menu = @"<td width='50%' align='center'>
                                        <a href='{0}' title='{1}'>
                                            <img src='{2}' width='264' height='139'/></a>
                                    </td>";
           // string strHas3Menu = "";
            List<MenuItem> menuList_2 = item.ChildMenu;
            int index = 0;
            string strItem = "";
            string strRow = "";
            foreach (MenuItem item_2 in menuList_2)
            {   
                if (item_2.HasChildMenu)//有三级菜单
                {
                    foreach (MenuItem item_3 in item_2.ChildMenu)
                    {
 
                    }
                }
                else//无三级菜单
                {
                    if (index == 2)
                    {
                        strRow += string.Format(strTableRow,strItem);
                        index = 1;
                        strItem = "";
                        strItem += string.Format(strNone3Menu, item_2.Link, item_2.Text, item_2.Image);
                    }
                    else
                    {
                        strItem += string.Format(strNone3Menu, item_2.Link, item_2.Text, item_2.Image);
                    }
                }
                index++;
            }
            Label li = new Label();
            li.Text = strTable_S + strRow + strTable_E;
            base.Controls.Add(li);

        }

        private void temp()
        {
            
        }
    }
}
